﻿namespace Ex04.Menus.Test
{
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Ex04.Menus.Interfaces;

    public class InterfaceMenu
    {
        #region Messages
        private const string k_Title = "~~~ Interface Main Menu ~~~";
        private const string k_Quit = "Quit";
        private const string k_Back = "Back";
        private const string k_ShowWelcomeMsg = "Show Welcome";
        private const string k_ShowDateTimeMsg = "Show Date/Time";
        private const string k_ShowVersionMsg = "Show Version";    
        private const string k_ShowDateMsg = "Show Date";
        private const string k_ShowTimeMsg = "Show Time";
        #endregion

        #region Data Members
        private readonly Menu r_MainMenu;
        #endregion

        #region Constructor
        public InterfaceMenu()
        {
            r_MainMenu = new Menu(k_Title, k_Quit);

            r_MainMenu.AddMenu(CreateOption1());
            r_MainMenu.AddMenu(CreateOption2());
            r_MainMenu.AddMenu(CreateOption3());
        }
        #endregion

        #region Public Methods
        public void StartMenu()
        {
            r_MainMenu.onSelect();
        }
        #endregion

        #region Private Methods
        private ISelector CreateOption1()
        {
            MenuItem newMenuItem;

            newMenuItem = new MenuItem(k_ShowWelcomeMsg);
            newMenuItem.setActionToExecute(new ShowWelcome());

            return newMenuItem;
        }

        private ISelector CreateOption2()
        {
            Menu newMenu;
            MenuItem newMenuItem;

            newMenu = new Menu(k_ShowDateTimeMsg, k_Back);
            newMenuItem = new MenuItem(k_ShowDateMsg);
            newMenuItem.setActionToExecute(new ShowDate());
            newMenu.AddMenu(newMenuItem);
            newMenuItem = new MenuItem(k_ShowTimeMsg);
            newMenuItem.setActionToExecute(new ShowTime());
            newMenu.AddMenu(newMenuItem);

            return newMenu;
        }

        private ISelector CreateOption3()
        {
            MenuItem newMenuItem;

            newMenuItem = new MenuItem(k_ShowVersionMsg);
            newMenuItem.setActionToExecute(new ShowVersion());

            return newMenuItem;
        }
        #endregion

        #region Actions
        public class ShowWelcome : IExecuter
        {
            public void ExecuteAction()
            {
                ExtentionFunctions.ShowWelcome();
            }
        }

        public class ShowVersion : IExecuter
        {
            public void ExecuteAction()
            {
                ExtentionFunctions.ShowVersion();
            }
        }

        public class ShowDate : IExecuter
        {
            public void ExecuteAction()
            {
                ExtentionFunctions.ShowDate();
            }
        }

        public class ShowTime : IExecuter
        {
            public void ExecuteAction()
            {
                ExtentionFunctions.ShowTime();
            }
        }

        #endregion
    }
}
